
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0836
 * @Author : WangRuoyu 
 * @Date : 2023/5/21 15:22
 */

#include "iostream"

using namespace std;
const int N = 1e5 + 10;
int f[N];

int find(int x) {
    if (f[x] != x) f[x] = find(f[x]);
    return f[x];
}

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 1; i < N; ++i) {
        f[i] = i;
    }

    for (int i = 0; i < k; ++i) {
        char op;
        int a, b;
        cin >> op >> a >> b;
        if (op == 'M') {
            f[find(a)] = find(b);
        } else {
            if (find(a) == find(b)) {
                puts("Yes");
            } else {
                puts("No");
            }
        }
    }

    return 0;
}